package com.ayu.gulimall.product.web;


import com.ayu.gulimall.product.entity.CategoryEntity;
import com.ayu.gulimall.product.service.CategoryService;
import com.ayu.gulimall.product.vo.Catalog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/index.html","/"})
    public String indexPage(Model model){

        //获得一级菜单返回
        List<CategoryEntity> catListLv1=categoryService.getLevel1Categories();
        model.addAttribute("catListLv1",catListLv1);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catalog2VO>> getCataLogJson(){
        //得到二三级菜单的数据
        Map<String, List<Catalog2VO>> map = categoryService.getLevel2Categories();

        return map;
    }
}
